package cake;

import user.DBCoon;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class CakeDaoImpl implements CakeDao{
    private String sql;

    public List<Cake> getCakeAll(){

        List<Cake> cakes = new ArrayList<Cake>();

        try{
            DBCoon.init();
            sql = "select * from cake where id>1";
            ResultSet rs = DBCoon.getUsers(sql);
            System.out.println("查询成功");
            while (rs.next()){
                Cake cake = new Cake();
                cake.getId();
                cake.getShop();
                cake.getDetail();
                cake.getPrice();
                cake.getNum();
                cakes.add(cake);
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            DBCoon.close();
        }
        return cakes;
    }

    @Override
    public int deleteCake(String id) {
        int i=0;
        try {
            DBCoon.init();
            sql = "delete from shop where id = ?";
            Object[] args = {id};
            i = DBCoon.addUpdDel(sql,args);
            if (i>0){
                System.out.println("删除成功");
            }
        }catch (Exception e) {
            System.out.println("删除失败");
            e.printStackTrace();
        }finally {
            DBCoon.close();
        }
        return i;
    }


}
